<?php
/**
 *
 */
namespace Addons\ThreeWords\Model;
use Think\Model;

/**
 * Class ThreeWordsModel  三字评论模型
 * @package Addons\ThreeWords\Model
 * @author:xjw129xjt xjt@ourstu.com
 */
class ThreeWordsCommentModel extends Model {
    protected $tableName = 'three_words_comment';
    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('status', '1', self::MODEL_INSERT),
    );

    protected $insertFields = 'uid,model,word_id,row_id';
    protected $updateFields = 'uid,model,word_id,row_id';

    public function addComment($data){
        $data = $this->create($data);
        $res = $this->add($data);
        return $res;
    }
public function delComment($id){
    $res = $this->where(array('id'=>$id))->setField('status',0);
    return $res;
}

    public function getCommentById($id){
        $comment = $this->where(array('id'=>$id,'status'=>1))->find();
        return $comment;
    }
    public function getComment($map='',$page=1,$limit=10,$order='id desc'){
        $map['status']=1;
        $comment = $this->where($map)->order($order)->page($page,$limit)->select();
        foreach($comment as &$v){
            $v['user'] = query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature','address','doing'), $v['uid']);
            $v['word'] = D('Addons://ThreeWords/ThreeWords')->getWord($v['word_id']);
        }
        return $comment;
    }

    public function getCount($map){
        $map['status']=1;
        $count = $this->where($map)->count();
        return $count;
    }
}